module stopwatch_plus (
  clk, ButtonIn,
  a, b, c, d, e, f, g, dp,
  pos, reset
);

  parameter sim = 0;
  input clk, ButtonIn, reset;
  output a, b, c, d, e, f, g, dp;
  output [3:0] pos;

  wire pulse400Hz, pulse10Hz;
  wire ButtonOut, clr, show;
  wire [1:0] count;
  wire[3:0] da0, da1, da2, da3;
  wire[3:0] db0, db1, db2, db3;

  // 分频器1
  counter_n #(.n(sim?2:250000), .counter_bits(sim?1:18)) Div1(
    .clk(clk), .en(0'b1), .r(0'b0), .q(), .co(pulse400Hz)
  );

  // 分频器2
  counter_n #(.n(sim?10:40), .counter_bits(sim?4:6)) Div2(
    .clk(clk), .en(pulse400Hz), .r(0'b0), .co(pulse10Hz)
  );

  button_unit #(.sim(sim)) buttonInst(
    .clk(clk), .reset(reset), .ButtonIn(ButtonIn), .ButtonOut(ButtonOut)
  );

  control_plus controlInst(
    .clk(clk), .reset(reset), .in(ButtonOut), .clr(clr), .count(count), .show(show)
  );

  // 计时器甲
  timing timingInst1(
    .clk(clk), .r(clr), .en(pulse10Hz&count[1]), .q0(da0), .qs({da2,da1}), .qm(da3)
  );
  // 计时器乙
  timing timingInst2(
    .clk(clk), .r(clr), .en(pulse10Hz&count[0]), .q0(db0), .qs({db2,db1}), .qm(db3)
  );

  display displayInst(
    .clk(clk), .scan(pulse400Hz), 
    .d0(show?da0:db0), .d1(show?da1:db1), .d2(show?da2:db2), .d3(show?da3:db3),
    .a(a), .b(b), .c(c), .d(d), .e(e), .f(f), .g(g),
    .pos(pos)
  );

  assign dp = pos[1];

    
endmodule